import axios from "axios";
import store from "../store";

//axios.default.baseURL = "";
//axios.create({ 配置对象 }) == > 创建一个新的axios实例对象
let request = axios.create({
    baseURL: "http://toutiao.itheima.net",
});

// ===============请求拦截器=================
request.interceptors.request.use(
    (config) => {
        // 一定要return config
        console.log("所有的请求头都走这里", config);
        // 如果你登录了，你就带上token！
        if (store.getters.token) {
            config.headers.Authorization = "Bearer " + store.getters.token;
        }
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
);
// ===============响应拦截器=================
export default request;